# Edit here as necessary:
CC = gcc
CFLAGS = -g -Wall -Iincludes

.PHONY: all examples

all: libs/libsharp.a

examples: libs/libsharp.a glob_example linkedlist_example keylist_example rng_example

libs/libsharp.a: build/alloc.o build/glob.o build/dynamicarray.o build/keylist.o build/linkedlist.o build/rng.o 
	mkdir -p libs
	ar rcs libs/libsharp.a build/*.o

build/alloc.o: src/alloc.c
	mkdir -p build
	$(CC) $(CFLAGS) -c -o build/alloc.o src/alloc.c

build/glob.o: src/glob.c
	mkdir -p build
	$(CC) $(CFLAGS) -c -o build/glob.o src/glob.c

build/dynamicarray.o: src/dynamicarray.c
	mkdir -p build
	$(CC) $(CFLAGS) -c -o build/dynamicarray.o src/dynamicarray.c

build/linkedlist.o: src/linkedlist.c
	mkdir -p build
	$(CC) $(CFLAGS) -c -o build/linkedlist.o src/linkedlist.c

build/keylist.o: src/keylist.c
	mkdir -p build
	$(CC) $(CFLAGS) -c -o build/keylist.o src/keylist.c

build/rng.o: src/rng.c
	mkdir -p build
	$(CC) $(CFLAGS) -c -o build/rng.o src/rng.c

clean:
	rm -rf build/
	rm -rf libs/
	rm -rf examples/bin/

glob_example: libs/libsharp.a
	mkdir -p examples/bin
	$(CC) $(CFLAGS) -o examples/bin/glob_example -Llibs/ -Iincludes/ examples/glob_example.c -lsharp

linkedlist_example: libs/libsharp.a
	mkdir -p examples/bin
	$(CC) $(CFLAGS) -o examples/bin/linkedlist_example -Llibs/ -Iincludes/ examples/linkedlist_example.c -lsharp

keylist_example: libs/libsharp.a
	mkdir -p examples/bin
	$(CC) $(CFLAGS) -o examples/bin/keylist_example -Llibs/ -Iincludes/ examples/keylist_example.c -lsharp

rng_example: libs/libsharp.a
	mkdir -p examples/bin
	$(CC) $(CFLAGS) -o examples/bin/rng_example -Llibs/ -Iincludes/ examples/rng_example.c -lsharp

